<template>
    <div class="detailPage">
        <van-nav-bar
		title="已建纪念馆管理"
		left-arrow
		@click-left="onClickLeft"
		/>
        <van-cell-group class="group">
            <van-cell title="查看纪念馆" is-link @click="jinianguanC"/>
            <van-cell title="墓园ID" :value="data.id + '' + data.userid + '' + data.id + '' +data.userid" />
            <van-cell is-link @click="payPage">
                <template slot="title">
                    <span class="van-cell-text">升级纪念馆</span>
                    <van-tag type="danger" v-show="data.memorialtype == 0">免费馆</van-tag>
                    <van-tag type="danger" v-show="data.memorialtype == 1">高档墓园</van-tag>
                    <van-tag type="danger" v-show="data.memorialtype == 2">陵园</van-tag>
                    <van-tag type="danger" v-show="data.memorialtype == 3">纪念堂</van-tag>
                </template>
            </van-cell>
            <van-cell title="背景修改" is-link @click="modify"/>
            <van-cell title="墓园建设修改" is-link @click="modify"/>
            <van-cell is-link @click="upvideo">
                <template slot="title">
                    <span class="van-cell-text">影像升级</span>
                    <van-tag type="danger" v-show="data.movicetype == 0">免费</van-tag>
                    <van-tag type="danger" v-show="data.movicetype == 1">收费200元</van-tag>
                    <van-tag type="danger" v-show="data.movicetype == 2">收费500元</van-tag>
                    <van-tag type="danger" v-show="data.movicetype == 3">收费1000元</van-tag>
                </template>
            </van-cell>
            <van-cell is-link @click="music">
                <template slot="title">
                    <span class="van-cell-text">音乐升级</span>
                    <van-tag v-if="data.musicstatus != 1">暂未选择</van-tag>
                    <van-tag v-else type="danger">已选择</van-tag>
                </template>
            </van-cell>
            <van-cell is-link @click="strightVideo">
                <template slot="title">
                    <span class="van-cell-text">直播升级</span>
                    <van-tag v-if="data.livemvdays == undefined">暂未选择</van-tag>
                    <van-tag v-else type="danger">{{data.livemvdays}}天</van-tag>
                </template>
            </van-cell>
            <van-cell title="吊唁密码设置及修改" is-link @click="setPassword"/>
            <van-field
                v-model="data.livemsg"
                label="生平简介"
                type="textarea"
                placeholder="请输入生平简介"
                rows="1"
                autosize
            />
            <van-field
                v-model="data.epitaph"
                label="吊唁日程"
                type="textarea"
                placeholder="请输入吊唁日程"
                rows="1"
                autosize
            />
            <van-field
                v-model="data.condolencesdate"
                label="墓志铭"
                type="textarea"
                placeholder="请输入墓志铭"
                autosize
                rows="1"
            />
            <van-cell title="生前相册" is-link @click="toPhoto('生前相册')"/>
            <van-cell title="生前视频" is-link @click="toVideo('生前视频')"/>
            <van-cell title="吊唁视频" is-link @click="toVideo('吊唁视频')"/>
            <van-cell title="吊唁影集" is-link @click="toPhoto('吊唁影集')"/>
            <van-cell title="祭奠视频" is-link @click="toVideo('祭奠视频')"/>
            <van-cell title="祭奠留影" is-link @click="toPhoto('祭奠留影')"/>
            <!-- <van-cell is-link @click="condolenceC">
                <template slot="title">
                    <span class="van-cell-text">吊唁馆展示</span>
                    <van-tag v-if="true">未开通</van-tag>
                    <van-tag type="danger" v-else>已开通</van-tag>
                </template>
            </van-cell> -->
            <van-cell is-link @click="toVideo('直播')">
                <template slot="title">
                    <span class="van-cell-text">直播</span>
                    <van-tag v-if="data.livemvdays == undefined">暂无</van-tag>
                    <van-tag v-else type="danger">点击查看</van-tag>
                </template>
            </van-cell>
            <van-cell is-link @click="moneyC">
                <template slot="title">
                    <span class="van-cell-text">吊唁礼金</span>
                    <van-tag v-show="data.condopay == 0">未开通</van-tag>
                    <van-tag type="danger" v-show="data.condopay == 1">已开通</van-tag>
                </template>
            </van-cell>
        </van-cell-group>
        <van-button size="large" @click="save">保存</van-button>
        <van-goods-action-mini-btn icon="cart" @click="car"/>
    </div>
</template>

<script>
export default {
    data () {
        return {
            live: '',
            richeng: '',
            muzhim: '',
            jianjie: '',
            data: {},
            choosemusic: false,
            mid: this.$route.query.id,
            goodname:"开通音乐",
            goodprice:100,
            goodnum:1,
            gooddesc:"可以在墓园中选择播放音乐",
            datalength: 0
        }
    },
    created () {
        this.data = JSON.parse(window.localStorage.getItem('item'))
        console.log(this.data)
        if (window.localStorage.getItem('memorialtype') != undefined ) {
            this.data.memorialtype = window.localStorage.getItem('memorialtype')
        }
        if (window.localStorage.getItem('movicetype') != undefined ) {
            this.data.movicetype = window.localStorage.getItem('movicetype')
        }
        if (window.localStorage.getItem('choosemusic') != undefined ) {
            this.data.musicstatus = 1
        }
        if (window.localStorage.getItem('strightVideoDay') != undefined ) {
            this.data.livemvdays = window.localStorage.getItem('strightVideoDay')
            this.data.livemv = true
        }
        
        // console.log())
         this.getCarList()
        
    },
    methods: {
        save () {
            
            if (window.localStorage.getItem('password') != undefined ) {
                this.data.condolencespwd = window.localStorage.getItem('password')
                // this.data.livemv = true
            }else {
                this.data.condolencespwd = this.data.condolencespwd
            }
           
            var that = this
            console.log(that.datalength)
            if (that.datalength > 0) {
                 
				that.$dialog.confirm({
					title: '保存升级',
					message: '确认选择后，将跳转购物车页面，付款完成后，完成升级，是否继续？'
				}).then(() => {
					that.$router.push({
                        path: '/car',
                        query: {
                            data: that.data
                        }
                    })
				}).catch(() => {
					// on cancel
				});
            } else {
                that.$axios.get("/huainianwang/memorial/app/updateMemorialInfo?mid="+this.mid+"&livemvdays="+this.data.livemvdays+"&livemv="+this.data.livemv+"&condolencespwd="+this.data.condolencespwd+"&condopay="+this.data.condopay+"&livemsg="+this.data.livemsg+"&epitaph="+this.data.epitaph+"&condolencesdate="+this.data.condolencesdate+"&memorialtype="+this.data.memorialtype+"&movicetype="+this.data.movicetype+"&condolencespwd="+this.data.condolencespwd+"&musicstatus="+this.data.musicstatus+"")
					.then(function(res){
						// alert(1)
						that.$router.push('/')
					},function(err){
					}).catch(function(error){
					});
            }
           
        },
        jinianguanC () {
            this.$router.push('/jininaguan')
        },
        modify () {
            this.$router.push('/building-edit')
        },
        moneyC () {
             this.$dialog.confirm({
                title: '开通吊唁礼金',
                message: '是否选择开通音乐服务，本栏将代为吊唁馆用户代收吊唁礼金，并按代收总额的2%收取服务费后全额返还馆主微信账户！'
            }).then(() => {
                // on close
               this.$toast('开通成功')
                this.data.condopay = 1
            }).catch(() => {
                // on cancel
            });
        },
        condolenceC () {
            this.$dialog.confirm({
                title: '开通吊唁馆',
                message: '限未出殡逝者，最多展示7天，选择吊唁馆后会在墓园首页展示：直播、吊唁礼金'
            }).then(() => {
                // on close
               this.$toast('开通成功')
                // this.data.condopay = 1
            }).catch(() => {
                // on cancel
            });
        },
        onClickLeft () {
            this.$dialog.confirm({
                title: '返回',
                message: '返回将取消当前保存的升级内容，是否继续'
            }).then(() => {
                window.localStorage.removeItem('memorialtype')
                window.localStorage.removeItem('movicetype')
                window.localStorage.removeItem('choosemusic')
                window.localStorage.removeItem('strightVideoDay')
                
                this.$axios.get("/huainianwang/shoppingCart/app/delAllShoppingCart?mid="+this.mid+"")
                    .then(function(res){
                        // alert(1)
                        that.$toast('已清空购物车')
                    },function(err){
                    }).catch(function(error){
                    });
                this.$router.push('/')
            }).catch(() => {
                // on cancel
            });
        },
        getCarList () {
          let that = this
          this.$axios.get("/huainianwang/shoppingCart/app/getShoppingCartByMid?mid="+this.mid+"")
				.then(function(res){
                    that.datalength = res.data.object.length
                    console.log(that.datalength)
				},function(err){
				}).catch(function(error){
				});
        },
        setPassword () {
            this.$router.push({
                path: '/set-password',
                query: {
                    password: this.data.condolencespwd
                }
            })
        },
        upvideo () {
            this.$router.push({
                path: '/up-video',
                query: {
                    value: this.data.movicetype
                }
            })
        },
        car () {
            this.$router.push('/car')
        },
        payPage () {
            this.$router.push({
                path: '/pay-page',
                query: {
                    value: this.data.memorialtype
                }
            })
        },
        toPhoto (title) {
            this.$router.push({
                path: '/photo',
                query: {
                    title: title
                }
            })
        },
        toVideo (title) {
            this.$router.push({
                path: '/video',
                query: {
                    title: title
                }
            })
        },
        music () {
            let that = this
            if (this.data.musicstatus != 1) {
                this.$dialog.confirm({
                    title: '音乐升级',
                    message: '是否选择开通音乐服务，开通费用100元'
                }).then(() => {  
                    window.localStorage.setItem('choosemusic', true)
                    this.data.musicstatus = 1
                    this.$axios.get("/huainianwang/shoppingCart/app/addShoppingCart?mid="+this.mid+"&goodname="+this.goodname+"&goodprice="+this.goodprice+"&goodnum="+this.goodnum+"&gooddesc="+this.gooddesc+"")
                    .then(function(res){
                        // alert(1)
                        that.$toast('请您在墓园建设中挑选音乐')
                    },function(err){
                    }).catch(function(error){
                    });
                    // this.choosemusic = window.localStorage.getItem('choosemusic')
                }).catch(() => {
                    // on cancel
                });
            }
        },
        strightVideo () {
            // if (window.localStorage.getItem('strightVideoDay') == undefined) {
                this.$dialog.confirm({
                    title: '是否开通直播服务',
                    message: '开通直播服务后，100元一天，是否开通？'
                }).then(() => {
                    
                    this.$router.push({
                        path: '/stright-video',
                        query: {
                            day: this.data.livemvdays
                        }
                    })
                }).catch(() => {
                    // on cancel
                });
            // }
            
        }
    }
}
</script>

<style lang="scss" scoped>
.car {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #ccc;
    position: relative;
    bottom: 50px;
    .van-icon{
        color: #9e5b5b;
        font-size: 25px;
    }
}
.van-goods-action-mini-btn {
    color: #fff;
    position: fixed;
    right: 10px;
    top: 2px;
    z-index: 100;
    background-color:#31a2c8;
    height: 43px;
}
.van-goods-action-mini-btn::after{
    border-width: 0px;
}
</style>
